<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .image-item{
            display: block;
            height: 300px;
            margin-bottom: 50px;
        }
    </style>
</head>
<body>
    <img class="image-item" lazyload="true" src="" data-original="https://tse1-mm.cn.bing.net/th/id/R-C.13b398a73c65e2f076e0ae6b83aedc72?rik=93P5PWR7fWbVIw&riu=http%3a%2f%2f222.186.12.239%3a10010%2fyzbb_150305%2f001.jpg&ehk=m0OQrJ2h59Hrl05k%2bkOlYIeJvEWH7ZlcJXOnPLR6HW4%3d&risl=&pid=ImgRaw&r=0">
    <img class="image-item" lazyload="true" src="" data-original="https://uploadfile.bizhizu.cn/up/09/d1/c2/09d1c2060c6f63b33614e06a9c34deff.jpg">
    <img class="image-item" lazyload="true" src="" data-original="https://uploadfile.bizhizu.cn/up/7b/80/d0/7b80d0dc19aa6e63c1822dc2136e6a53.jpg">
    <img class="image-item" lazyload="true" src="" data-original="https://tse1-mm.cn.bing.net/th/id/R-C.8533c9c03929be226c9ee9158696bc41?rik=727oa7rGVVrvYg&riu=http%3a%2f%2fwww.ukutu.cn%2fupload%2f201510%2f16%2f20151016224933267.jpg&ehk=sXteGVvLo%2flNDPLUMqj6RWnIrgaEOWI8h7SYkF3yoYI%3d&risl=&pid=ImgRaw&r=0">
    <img class="image-item" lazyload="true" src="" data-original="https://img.walltu.com/d/file/meinv/2017-02-10/112843-xK3WQDk.jpg">
    <img class="image-item" lazyload="true" src="" data-original="https://tse1-mm.cn.bing.net/th/id/R-C.a6cb6274ce271d3d45454aba58acaa30?rik=rE3bzPxMSXS5wQ&riu=http%3a%2f%2fwww.ukutu.cn%2fupload%2f201602%2f27%2f20160227132203811.jpg&ehk=bRiO%2bYYmg0gor4ryYQO7boVFv8SLjRjG1dejgjPsWEs%3d&risl=&pid=ImgRaw&r=0">
    <img class="image-item" lazyload="true" src="" data-original="https://tse1-mm.cn.bing.net/th/id/R-C.3de5cff9b11f75bca4270b5896b95ec0?rik=Cg8T8WcSfCjZuw&riu=http%3a%2f%2fwww.ukutu.cn%2fupload%2f201510%2f05%2f20151005114415429.jpg&ehk=FSM9pY7s6pa%2b6tWzhxNmObMFCMlYuIbRjnYW%2bI8e9Sk%3d&risl=&pid=ImgRaw&r=0">
    <img class="image-item" lazyload="true" src="" data-original="https://tse1-mm.cn.bing.net/th/id/R-C.f87bb0af0eb90fc10ccead84bc318177?rik=b7ooNUfRaKWxNg&riu=http%3a%2f%2fwww.dnzhuti.com%2fuploads%2fallimg%2f180420%2f95-1P420152450.jpg&ehk=ov%2bzeRhxhxoI9srht1Dv%2f5oPj9jqk1oif8QU3%2beHC1M%3d&risl=&pid=ImgRaw&r=0">
    <img class="image-item" lazyload="true" src="" data-original="https://tse1-mm.cn.bing.net/th/id/R-C.97b88f615e823b030f4855e95176b64f?rik=ZvqhG7uGaR6%2f7A&riu=http%3a%2f%2fwww.ukutu.cn%2fupload%2f201510%2f06%2f201510060033267966.jpg&ehk=CAcePlaUhfc7JApAkC%2b6wUg0HtxauK6TaecBUf02LRI%3d&risl=&pid=ImgRaw&r=0">
    <img class="image-item" lazyload="true" src="" data-original="https://tse1-mm.cn.bing.net/th/id/R-C.f590053ffc03c18d98c532a9f1f58216?rik=bwQVRRGhT0Hmbg&riu=http%3a%2f%2fwww.ukutu.cn%2fupload%2f201511%2f16%2f2015111609381037.jpg&ehk=SWLff%2fFudwp3v5Tay2HXrRf6pDXDRPGGtRYnqytiB5I%3d&risl=&pid=ImgRaw&r=0">
    <img class="image-item" lazyload="true" src="" data-original="https://tse1-mm.cn.bing.net/th/id/R-C.817d64b20895ac46dea771a3f52452e3?rik=XIlEw6LxJMTMHg&riu=http%3a%2f%2fwww.dnzhuti.com%2fuploads%2fallimg%2f180614%2f95-1P614153150.jpg&ehk=Zk5BlFP0MenJ%2fuNrGJCto79XLkPrzMRrJv%2buherMxiA%3d&risl=&pid=ImgRaw&r=0">
    <img class="image-item" lazyload="true" src="" data-original="https://tse1-mm.cn.bing.net/th/id/R-C.e77007b00c5d0e02f2ca11614287274a?rik=a2fsjVkOfQjklA&riu=http%3a%2f%2fwww.ukutu.cn%2fupload%2f201510%2f05%2f20151005114405385.jpg&ehk=pfViA5CncZPV6UfPyU%2bbQb%2bCbuJAzncyKVGbb%2fw%2bEkg%3d&risl=&pid=ImgRaw&r=0">
    <script>
        let viewHeight = document.documentElement.clientHeight
        // console.log(viewHeight);
    
        function lasyLoad() {
            let eles = document.querySelectorAll('img[data-original][lazyload]')
            // console.log(eles);
    
            eles.forEach(item => {
                // console.log(item);
                let rect;
                rect = item.getBoundingClientRect()
                if (rect.bottom >= 0 && rect.top < viewHeight) { // 在可视区域内
                    let img = new Image()
                    img.src = item.dataset.original
                    item.src = item.dataset.original
                    img.onload = function() {
                        item.src = img.src
                    }
                    item.removeAttribute('data-original')
                    item.removeAttribute('lazyload')
                }
            })
        }
        lasyLoad()
        document.addEventListener('scroll',lasyLoad)
    </script>
</body>
</html>